//
//  HLTwangjipasswordTableViewCell.m
//  huiliantong
//
//  Created by hlt on 15/8/31.
//  Copyright (c) 2015年 hlt. All rights reserved.
//

#import "HLTwangjipasswordTableViewCell.h"
#import "HLTwangjixiugaiTableViewController.h"
@implementation HLTwangjipasswordTableViewCell

- (void)awakeFromNib {
    // Initialization code
    [self creatcs];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}


- (void)btnAction:(id)sender {
    
    
    
    NSString *url=[wangjiyanzhengma stringByAppendingFormat:@"&mobile=%@&flag=forget&id_card=%@",self.username.text,self.usercode.text];
    [HLTNetWorkingtool getdic:url success:^(NSDictionary *ary) {
    
        
        NSLog(@"aa%@aa",ary[@"code"]);
        NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init];
        NSString *str123 = [numberFormatter stringFromNumber:ary[@"code"]];
        NSString *sstr=@"2";
//        NSLog(@"123%@123%@456",str123,sstr);
        if ([str123 isEqual:sstr]) {
            //发送验证码成功
            self.yanzhengma1=ary[@"mobile_code"];
            
            UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"发送验证码成功"   message:nil delegate:nil cancelButtonTitle:@"好" otherButtonTitles: nil];
            [alert show];
            
        }
        else
        {
            UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"发送验证码失败"   message:ary[@"msg"]  delegate:nil cancelButtonTitle:@"好" otherButtonTitles: nil];
            [alert show];
            
        }
        
        
        
    } faliure:^(NSString *error) {
        
        
    }];
    
    
    NSLog(@"click");
    JxbScaleButton* btn = (JxbScaleButton*)sender;
    JxbScaleSetting* setting = [[JxbScaleSetting alloc] init];
    setting.strPrefix = @"";
    setting.strSuffix = @"秒";
    setting.strCommon = @"重新发送";
    setting.indexStart = 60;
    [btn startWithSetting:setting];
}

- (void)creatcs {
    
    
    JxbScaleButton* btn = [[JxbScaleButton alloc] initWithFrame:CGRectMake(0, 0, self.fasongview.frame.size.width, self.fasongview.frame.size.height)];
    btn.layer.cornerRadius = 5;
    btn.layer.masksToBounds = YES;
    btn.titleLabel.font=[UIFont systemFontOfSize: 14.0];
    [btn setTitle: @"获取验证码" forState: UIControlStateNormal];
    btn.backgroundColor=navigationBarColor;
    [self.fasongview addSubview:btn];
    
    //    [self btnAction:btn];
    
    [btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
}








- (IBAction)tijiao:(id)sender {
    
    

    
    if ([self.yanzhengma.text isEqual:self.yanzhengma1]) {
        
        
        [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
        
        UIView *view1=[[UIView alloc] initWithFrame:self.parent.view.bounds];
        view1.backgroundColor=[UIColor grayColor];
        view1.alpha=0.4;
        [self.parent.view addSubview:view1];
        MONActivityIndicatorView *indicatorView = [[MONActivityIndicatorView alloc] init];
        indicatorView.delegate = self;
        indicatorView.numberOfCircles = 3;
        indicatorView.radius = 20;
        indicatorView.internalSpacing = 3;
        indicatorView.center = self.parent.view.center;
        [indicatorView startAnimating];
        [self.parent.view addSubview:indicatorView];
        
    
    NSString *url=[wangjitijiao stringByAppendingFormat:@"&username=%@&id_num=%@",self.username.text,self.usercode.text];
    [HLTNetWorkingtool getary:url success:^(NSArray *ary) {
       
        
        if ([ary[0][@"msg"] isEqual:@"0"]) {
         //提交成功
            
            UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            HLTwangjixiugaiTableViewController *vc = [storyBoard instantiateViewControllerWithIdentifier:@"HLTwangjixiugaiTableViewController"];
//            [self.parent.navigationController popViewControllerAnimated:YES];
            
            vc.username=self.username.text;
            [self.parent.navigationController pushViewController:vc animated:NO];
            [indicatorView stopAnimating];
            [view1 removeFromSuperview];

        }
        else
        {
            UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"验证码输入错误"   message:@"请重新输入" delegate:nil cancelButtonTitle:@"好" otherButtonTitles: nil];
            [alert show];
            [indicatorView stopAnimating];
            [view1 removeFromSuperview];

        }
        
    } faliure:^(NSString *error) {
        
        [indicatorView stopAnimating];
        [view1 removeFromSuperview];

    }];
    
    }
    else
    {
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"验证码输入错误"   message:@"请重新输入" delegate:nil cancelButtonTitle:@"好" otherButtonTitles: nil];
                    [alert show];
        
    }
    
}




#pragma mark - MONActivityIndicatorViewDelegate Methods

- (UIColor *)activityIndicatorView:(MONActivityIndicatorView *)activityIndicatorView
      circleBackgroundColorAtIndex:(NSUInteger)index {
    CGFloat red   = (arc4random() % 256)/255.0;
    CGFloat green = (arc4random() % 256)/255.0;
    CGFloat blue  = (arc4random() % 256)/255.0;
    CGFloat alpha = 1.0f;
    return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}








@end
